Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions elftools/construct/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@
http://construct.wikispaces.com (including online tutorial)

Typical usage:
>>> from construct import *
>>> from ..construct import *

Hands-on example:
>>> from construct import *
>>> from ..construct import *
>>> s = Struct("foo",
... UBInt8("a"),
... UBInt16("b"),
... )
>>> s.parse("\\x01\\x02\\x03")
Container(a = 1, b = 515)
>>> print(s.parse("\\x01\\x02\\x03"))
Container:
a = 1
b = 515
>>> s.build(Container(a = 1, b = 0x0203))
"\\x01\\x02\\x03"
>>> s.parse(b"\\x01\\x02\\x03")
Container({'a': 1, 'b': 515})
>>> print(s.parse(b"\\x01\\x02\\x03"))
Container({'a': 1, 'b': 515})
>>> s.build(Container(a=1, b=0x0203))
b'\\x01\\x02\\x03'
"""
from __future__ import annotations

from .lib.container import *
from .core import *
from .adapters import *
from .macros import *
Expand All @@ -39,9 +39,9 @@
#===============================================================================
# Metadata
#===============================================================================
__author__ = "tomer filiba (tomerfiliba [at] gmail.com)"
__maintainer__ = "Corbin Simpson <[email protected]>"
__version__ = "2.06"
__author__: str = "tomer filiba (tomerfiliba [at] gmail.com)"
__maintainer__: str = "Corbin Simpson <[email protected]>"
__version__: str = "2.06"

#===============================================================================
# Shorthand expressions
Expand All @@ -59,10 +59,20 @@
#===============================================================================
import functools
import warnings
from typing import TYPE_CHECKING, TypeVar

def deprecated(f):
if TYPE_CHECKING:
from collections.abc import Callable

from typing_extensions import ParamSpec

_P = ParamSpec('_P')
_T = TypeVar('_T')


def deprecated(f: Callable[_P, _T]) -> Callable[_P, _T]:
@functools.wraps(f)
def wrapper(*args, **kwargs):
def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> _T:
warnings.warn(
"This name is deprecated, use %s instead" % f.__name__,
DeprecationWarning, stacklevel=2)
Expand Down
Loading