A system for Python that generates static type annotations by collecting runtime types

Overview

MonkeyType

MonkeyType collects runtime types of function arguments and return values, and can automatically generate stub files or even add draft type annotations directly to your Python code based on the types collected at runtime.

Example

Say some/module.py originally contains:

def add(a, b):
    return a + b

And myscript.py contains:

from some.module import add

add(1, 2)

Now we want to infer the type annotation of add in some/module.py by running myscript.py with MonkeyType. One way is to run:

$ monkeytype run myscript.py

By default, this will dump call traces into a SQLite database in the file monkeytype.sqlite3 in the current working directory. You can then use the monkeytype command to generate a stub file for a module, or apply the type annotations directly to your code.

Running monkeytype stub some.module will output a stub:

def add(a: int, b: int) -> int: ...

Running monkeytype apply some.module will modify some/module.py to:

def add(a: int, b: int) -> int:
    return a + b

This example demonstrates both the value and the limitations of MonkeyType. With MonkeyType, it's very easy to add annotations that reflect the concrete types you use at runtime, but those annotations may not always match the full intended capability of the functions. For instance, add is capable of handling many more types than just integers. Similarly, MonkeyType may generate a concrete List annotation where an abstract Sequence or Iterable would be more appropriate. MonkeyType's annotations are an informative first draft, to be checked and corrected by a developer.

Motivation

Readability and static analysis are the primary motivations for adding type annotations to code. It's already common in many Python style guides to document the argument and return types for a function in its docstring; annotations are a standardized way to provide this documentation, which also permits static analysis by a typechecker such as mypy.

For more on the motivation and design of Python type annotations, see PEP 483 and PEP 484.

Requirements

MonkeyType requires Python 3.6+ and the libcst library (for applying type stubs to code files). It generates only Python 3 type annotations (no type comments).

Installing

Install MonkeyType with pip:

pip install MonkeyType

How MonkeyType works

MonkeyType uses the sys.setprofile hook provided by Python to interpose on function calls, function returns, and generator yields, and record the types of arguments / return values / yield values.

It generates stub files based on that data, and can use libcst to apply those stub files directly to your code.

See the full documentation for details.

Troubleshooting

Check if your issue is mentioned in the frequently asked questions list.

Development

See CONTRIBUTING.rst for information on developing and contributing to MonkeyType.

LICENSE

MonkeyType is BSD licensed.

Comments
  • Python 3.9 AttributeError: __args__

    Python 3.9 AttributeError: __args__

    I honestly cannot parse this error message.

    I'm trying to run monkeytype on manim's mobject.py

    monkeytype stub manim.mobject.mobject
    
    Traceback (most recent call last):
      File "C:\Python39\lib\runpy.py", line 197, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "C:\Python39\lib\runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "C:\Users\ethan\AppData\Local\pypoetry\Cache\virtualenvs\manim-ob3XvX2_-py3.9\Scripts\monkeytype.exe\__main__.py", line 7, in <module>
      File "c:\users\ethan\appdata\local\pypoetry\cache\virtualenvs\manim-ob3xvx2_-py3.9\lib\site-packages\monkeytype\cli.py", line 396, in entry_point_main
        sys.exit(main(sys.argv[1:], sys.stdout, sys.stderr))
      File "c:\users\ethan\appdata\local\pypoetry\cache\virtualenvs\manim-ob3xvx2_-py3.9\lib\site-packages\monkeytype\cli.py", line 381, in main
        handler(args, stdout, stderr)
      File "c:\users\ethan\appdata\local\pypoetry\cache\virtualenvs\manim-ob3xvx2_-py3.9\lib\site-packages\monkeytype\cli.py", line 199, in print_stub_handler
        stub = get_stub(args, stdout, stderr)
      File "c:\users\ethan\appdata\local\pypoetry\cache\virtualenvs\manim-ob3xvx2_-py3.9\lib\site-packages\monkeytype\cli.py", line 126, in get_stub
        stubs = build_module_stubs_from_traces(
      File "c:\users\ethan\appdata\local\pypoetry\cache\virtualenvs\manim-ob3xvx2_-py3.9\lib\site-packages\monkeytype\stubs.py", line 819, in build_module_stubs_from_traces
        return build_module_stubs(defns)
      File "c:\users\ethan\appdata\local\pypoetry\cache\virtualenvs\manim-ob3xvx2_-py3.9\lib\site-packages\monkeytype\stubs.py", line 784, in build_module_stubs
        imports = get_imports_for_signature(entry.signature)
      File "c:\users\ethan\appdata\local\pypoetry\cache\virtualenvs\manim-ob3xvx2_-py3.9\lib\site-packages\monkeytype\stubs.py", line 157, in get_imports_for_signature
        param_imports = get_imports_for_annotation(param.annotation)
      File "c:\users\ethan\appdata\local\pypoetry\cache\virtualenvs\manim-ob3xvx2_-py3.9\lib\site-packages\monkeytype\stubs.py", line 143, in get_imports_for_annotation
        elem_types = anno.__args__ or []
      File "C:\Python39\lib\typing.py", line 694, in __getattr__
        raise AttributeError(attr)
    AttributeError: __args__
    
    opened by GameDungeon 28
  • TypeVar instances also lack `__qualname__`

    TypeVar instances also lack `__qualname__`

    Sharing a quick fix I needed to get to work on some of the projects I quickly gave this a shot on. It choked on trying to serialize TypeVar instances as it seems like it also lacks __qualname__.

    CLA Signed 
    opened by vodik 18
  • Getting '_SpecialForm' object has no attribute '__name__'

    Getting '_SpecialForm' object has no attribute '__name__'

    I'm getting this error running monkeytype 21.5 on python 3.8:

    monkeytype run -m pytest tests
    Failed collecting trace
    Traceback (most recent call last):
      File "path\to\env\lib\site-packages\monkeytype\tracing.py", line 259, in __call__
        self.handle_call(frame)
      File "path\to\env\lib\site-packages\monkeytype\tracing.py", line 225, in handle_call
        arg_types[name] = get_type(frame.f_locals[name],
      File "path\to\env\lib\site-packages\monkeytype\typing.py", line 190, in get_type
        return get_dict_type(obj, max_typed_dict_size)
      File "path\to\env\lib\site-packages\monkeytype\typing.py", line 170, in get_dict_type
        val_type = shrink_types((get_type(v, max_typed_dict_size) for v in dct.values()), max_typed_dict_size)
      File "path\to\env\lib\site-packages\monkeytype\typing.py", line 133, in shrink_types
        annotation = shrink_types((getattr(typ, '__args__')[0] for typ in types), max_typed_dict_size)
      File "path\to\env\lib\site-packages\monkeytype\typing.py", line 132, in shrink_types
        if all(is_list(typ) for typ in types):
      File "path\to\env\lib\site-packages\monkeytype\typing.py", line 132, in <genexpr>
        if all(is_list(typ) for typ in types):
      File "path\to\env\lib\site-packages\monkeytype\typing.py", line 54, in is_list
        return is_generic(typ) and name_of_generic(typ) == 'List'
      File "path\to\env\lib\site-packages\monkeytype\compat.py", line 43, in name_of_generic
        return typ._name or typ.__origin__.__name__
    AttributeError: '_SpecialForm' object has no attribute '__name__'
    

    Using 20.5 works correctly instead. This happens while running monkeytype on alembic.

    To reproduce (commit e31971cfb46efd0ef41525473a1d9bcb81e90f43 is the current head of alembic):

    git clone https://github.com/sqlalchemy/alembic.git
    cd alembic
    git checkout e31971cfb46efd0ef41525473a1d9bcb81e90f43
    pip install -e .
    pip install python-dateutil
    monkeytype run -m pytest tests
    
    need-info 
    opened by CaselIT 12
  • Allow typing specified modules in site-packages

    Allow typing specified modules in site-packages

    #82

    This PR allows users to define an environment variable MONKEYTYPE_MODULE with name of a module, which would be typed by MonkeyType even if it is under Python site-packages.

    CLA Signed 
    opened by BoPeng 12
  • `monkeytype run manage.py test` doesn't produce sqllite file

    `monkeytype run manage.py test` doesn't produce sqllite file

    I've run monkeytype run manage.py test in my django project after pip install monkeytype (inside of a virtual env) and I'm not seeing any output of the sqllite file described in the README.

    Running monkeytype stub for any of my modules doesn't work either. If there's something different that I have to do for django tests, let's add that to the README. Otherwise, am I missing something?

    opened by nsillik 10
  • record per-key types for heterogenous dicts and suggest TypedDict annotation

    record per-key types for heterogenous dicts and suggest TypedDict annotation

    Currently MonkeyType assumes dicts are homogenous. When heterogenous dicts are seen, we just combine all the value types into a Union (and then if that Union gets too big, by default we rewrite it to Any). It'd be more useful in such cases to suggest a TypedDict annotation with per-key value types.

    The trick here is that we don't really know the intention, so there'd be some level of heuristic involved. Like, if there's multiple non-None value types (and probably if the number of keys is less than some threshold), rather than recording just a single value type, we record per-key value types. Then we'd also need some smarts when combining traces into an annotation: if we have any traces with per-key value types, try to construct a consistent TypedDict, but if we find that key names and value types aren't matching up consistently, fallback to normal Dict.

    There's enough fuzziness in the heuristics here and this'd be enough work that it might not be worth it, but for codebases that use lots of heterogenous dicts, it'd make the generated annotations a lot more useful.

    enhancement 
    opened by carljm 9
  • demo example tests are not passing at 100% on Windows

    demo example tests are not passing at 100% on Windows

    I tried to run the demo but I got:

    monkeytype\demo>pytest
    ============================= test session starts =============================
    platform win32 -- Python 3.6.1, pytest-3.5.0, py-1.5.3, pluggy-0.6.0
    rootdir: monkeytype\demo, inifile: pytest.ini
    plugins: cov-2.5.1
    collected 8 items
    
    test_inbox.py ......F.                                                   [100%]
    
    ================================== FAILURES ===================================
    _______________________________ test_everything _______________________________
    
        def test_everything():
            u = make_user()
            other = make_user(name="Other", following=[u.id])
            first_entry = make_feedentry(user_id=u.id, caption="My First Post")
            follow = make_followed(user_id=u.id, follower_id=other.id)
            second_entry = make_feedentry(user_id=u.id, caption="Second Post")
            like1 = make_liked(user_id=u.id, liker_id=other.id, feedentry_id=first_entry.id)
            comment = make_commented(
                user_id=u.id, commenter_id=other.id, feedentry_id=first_entry.id
            )
            like2 = make_liked(user_id=u.id, liker_id=other.id, feedentry_id=second_entry.id)
            repo = FakeRepo(u, other, first_entry, second_entry, like1, like2, comment, follow)
            box = inbox.Inbox(u, repo)
    
    >       assert (
                box.aggregate()
                == [
                    models.AggregatedItem(
                        type=models.EventType.LIKED,
                        text='Other liked your post "Second Post".',
                        published=like2.published,
                    ),
                    models.AggregatedItem(
                        type=models.EventType.COMMENTED,
                        text="Other commented on your post.",
                        published=comment.published,
                    ),
                    models.AggregatedItem(
                        type=models.EventType.LIKED,
                        text='Other liked your post "My First Post".',
                        published=like1.published,
                    ),
                    models.AggregatedItem(
                        type=models.EventType.FOLLOWED,
                        text="Other started following you.",
                        published=follow.published,
                    ),
                ]
            )
    E       assert [AggregatedIt... 26, 231564))] == [AggregatedIte... 26, 231564))]
    E         At index 0 diff: AggregatedItem(type=<EventType.COMMENTED: 'commented'>, text='Other commented on your post.', published=datetime.datetime(2018, 7, 25, 6, 38, 26, 231564)) != AggregatedItem(type=<EventType.LIKED: 'liked'>, text='Other liked your post "Second Post".', published=datetime.datetime(2018, 7, 25, 6, 38, 26, 231564))
    E         Use -v to get the full diff
    
    test_inbox.py:242: AssertionError
    
    ----------- coverage: platform win32, python 3.6.1-final-0 -----------
    Name       Stmts   Miss Branch BrPart  Cover   Missing
    ------------------------------------------------------
    inbox.py      87      2     33      1    98%   163-164, 160->163
    Coverage HTML written to dir htmlcov
    
    ===================== 1 failed, 7 passed in 0.38 seconds ======================
    
    monkeytype\demo>
    
    opened by bluebird75 9
  • MonkeyType is not working in IPython

    MonkeyType is not working in IPython

    The newer version of MonkeyType does not work in IPython. I think https://github.com/Instagram/MonkeyType/commit/e8bb8a687e18dbb3c734ef33501a573265465c9d could be the reason.

    An interactive session in IPython will assert __name__ == '__main__' it would still be meaningful to capture the CallTrace so folks could interactively type their notebook/python source.

    I can totally understand if this falls outside the scope of the project.

    bug 
    opened by tonyfast 9
  • cannot use MonkeyType on Azure App Services filesystem: `sqlite3.OperationalError: database is locked`

    cannot use MonkeyType on Azure App Services filesystem: `sqlite3.OperationalError: database is locked`

    I've been attempting to get MonkeyType 21.5.0 to work in AzureML, which uses Ubuntu VMs for compute instances. However, after multiple attempts in both Python 3.6.9 and 3.8.1, every command, version, and file I've tried returns the same error trace:

    Traceback (most recent call last):
      File "/anaconda/envs/azureml_py38/bin/monkeytype", line 8, in <module>
        sys.exit(entry_point_main())
      File "/anaconda/envs/azureml_py38/lib/python3.8/site-packages/monkeytype/cli.py", line 396, in entry_point_main
        sys.exit(main(sys.argv[1:], sys.stdout, sys.stderr))
      File "/anaconda/envs/azureml_py38/lib/python3.8/site-packages/monkeytype/cli.py", line 381, in main
        handler(args, stdout, stderr)
      File "/anaconda/envs/azureml_py38/lib/python3.8/site-packages/monkeytype/cli.py", line 210, in list_modules_handler
        modules = args.config.trace_store().list_modules()
      File "/anaconda/envs/azureml_py38/lib/python3.8/site-packages/monkeytype/config.py", line 147, in trace_store
        return SQLiteStore.make_store(db_path)
      File "/anaconda/envs/azureml_py38/lib/python3.8/site-packages/monkeytype/db/sqlite.py", line 82, in make_store
        create_call_trace_table(conn)
      File "/anaconda/envs/azureml_py38/lib/python3.8/site-packages/monkeytype/db/sqlite.py", line 45, in create_call_trace_table
        conn.execute(query)
    sqlite3.OperationalError: database is locked
    

    The sqlite3 DB is being created, but the connection isn't being closed correctly despite the with statement in line 44 of ./monkeytype/db/sqlite.py. Is there any way to config the context manager for the sqlite DB?

    opened by ColtAllen 8
  • monkeytype/typing.py import error in PyCharm

    monkeytype/typing.py import error in PyCharm

    Trying to set up dev environment per instructions in CONTRIBUTING.rst

    Getting an import error: Traceback (most recent call last): File "/home/johnar/github/MonkeyType/monkeytype/cli.py", line 17, in from typing import ( File "/home/johnar/github/MonkeyType/monkeytype/typing.py", line 10, in from typing import ( ImportError: cannot import name 'Any'

    In pycharm it actually shows that import _Any and _Union result in unresolved reference, as they're not defined in the typing module.

    This is with stdlib typing 3.6.4: typing 3.6.4

    opened by johnarnold 8
  • monkeytype / retype doesn't apply stubs in __init__.py

    monkeytype / retype doesn't apply stubs in __init__.py

    For one of my modules, I ran test cases via monketype run, I can see the traces in the sqlite3 database, and I can run 'monketype stub modulename' and see what looks like valid stub output.

    However, when I run 'monkeytype apply modulename', it returns no errors but the module is not modified.

    I've been able to successfully update other modules. This module is my only good repro so far. There are no errors anywhere. I'm open to ideas on how to proceed. I guess i can start with debugging monkeytype?

    bug 
    opened by johnarnold 8
  • Support PEP 604 Union syntax  (Union[a, b] → a | b)

    Support PEP 604 Union syntax (Union[a, b] → a | b)

    PEP 604 introduces a new Union syntax in Python 3.10+. It would be nice if Monkeytype could leverage that, and perhaps have a flag to use a union with None rather than the Optional type.

    # Old syntax
    def foo(a: Optional[Union[float, int]]) -> Optional[float]:
        ...
    
    # New syntax
    def foo(a: float | int | None) -> float | None:
        ...
    
    enhancement 
    opened by AllanLeanderRostockHansen 0
  • Traces with builtins.coroutine, builtins.async_generator fail to decode

    Traces with builtins.coroutine, builtins.async_generator fail to decode

    WARNING: Failed decoding trace: Module 'builtins' has no attribute 'async_generator'
    WARNING: Failed decoding trace: Module 'builtins' has no attribute 'async_generator'
    WARNING: Failed decoding trace: Module 'builtins' has no attribute 'async_generator'
    WARNING: Failed decoding trace: Module 'builtins' has no attribute 'coroutine'
    WARNING: Failed decoding trace: Module 'builtins' has no attribute 'coroutine'
    WARNING: Failed decoding trace: Module 'builtins' has no attribute 'coroutine'
    WARNING: Failed decoding trace: Module 'builtins' has no attribute 'coroutine'
    WARNING: Failed decoding trace: Module 'builtins' has no attribute 'coroutine'
    

    Got the above in verbose mode when running Python 3.6.15 and MonkeyType 21.5.0 .

    Should these be in the following? https://github.com/Instagram/MonkeyType/blob/cef09c6702fbab58e66582f76f2559d6a21e448c/monkeytype/encoding.py#L97-L102

    And are there any other async or builtin types that need this special handling?

    Even though traces that don't decode usually get ignored, async types are probably very meaningful for the codebase.

    bug 
    opened by slix 1
  • "Failed collecting trace" and then lots of exceptions

    Should be a pretty easy repro.

    Create a Dockerfile with the following contents:

    FROM ubuntu:20.04
    RUN apt-get update
    RUN apt-get install -y python3 python3-pip
    RUN pip3 install monkeytype
    RUN echo "from pkg_resources.extern import six" > repro.py
    

    Then build it with docker build --network=host -t repro . and start with docker run --rm -it repro bash (or whatever).

    Can verify that the import works correctly:

    root@2ed6e4080312:/# python3 repro.py
    root@2ed6e4080312:/#
    

    (python3 here is 3.8)

    But this doesn't work through MonkeyType:

    root@2ed6e4080312:/# monkeytype run repro.py
    Failed collecting trace
    Traceback (most recent call last):
      File "/usr/local/lib/python3.8/dist-packages/monkeytype/tracing.py", line 259, in __call__
        self.handle_call(frame)
      File "/usr/local/lib/python3.8/dist-packages/monkeytype/tracing.py", line 213, in handle_call
        func = self._get_func(frame)
      File "/usr/local/lib/python3.8/dist-packages/monkeytype/tracing.py", line 207, in _get_func
        self.cache[code] = get_func(frame)
      File "/usr/local/lib/python3.8/dist-packages/monkeytype/tracing.py", line 151, in get_func
        func = get_func_in_mro(first_arg, code)
      File "/usr/local/lib/python3.8/dist-packages/monkeytype/tracing.py", line 113, in get_func_in_mro
        val = inspect.getattr_static(obj, code.co_name, None)
      File "/usr/lib/python3.8/inspect.py", line 1596, in getattr_static
        instance_result = _check_instance(obj, attr)
      File "/usr/lib/python3.8/inspect.py", line 1546, in _check_instance
        return dict.get(instance_dict, attr, _sentinel)
    TypeError: descriptor 'get' for 'dict' objects doesn't apply to a 'NoneType' object
    ...
    ...
    
    bug 
    opened by EvanED 1
  • Less scary output on failed collecting trace warnings

    Less scary output on failed collecting trace warnings

    We don't need to print the full traceback, and we could probably hint people that even if a few traces failed to collect that doesn't mean useful type traces weren't still collected.

    See e.g. #244

    enhancement 
    opened by carljm 0
  • failed collecting trace: TypeError: descriptor 'get' for 'dict' objects doesn't apply to a 'NoneType' object

    failed collecting trace: TypeError: descriptor 'get' for 'dict' objects doesn't apply to a 'NoneType' object

    First time using this tool, after watching the utoob discussion. No type info whatsoever in my code, but I was prepared to be converted, and was interested to get a leg up with this tool.

    monkeytype run zwi/zwi.py Failed collecting trace Traceback (most recent call last): File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 259, in __call__ self.handle_call(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 213, in handle_call func = self._get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 207, in _get_func self.cache[code] = get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 151, in get_func func = get_func_in_mro(first_arg, code) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 113, in get_func_in_mro val = inspect.getattr_static(obj, code.co_name, None) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1622, in getattr_static instance_result = _check_instance(obj, attr) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1572, in _check_instance return dict.get(instance_dict, attr, _sentinel) TypeError: descriptor 'get' for 'dict' objects doesn't apply to a 'NoneType' object Failed collecting trace Traceback (most recent call last): File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 259, in __call__ self.handle_call(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 213, in handle_call func = self._get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 207, in _get_func self.cache[code] = get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 151, in get_func func = get_func_in_mro(first_arg, code) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 113, in get_func_in_mro val = inspect.getattr_static(obj, code.co_name, None) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1622, in getattr_static instance_result = _check_instance(obj, attr) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1572, in _check_instance return dict.get(instance_dict, attr, _sentinel) TypeError: descriptor 'get' for 'dict' objects doesn't apply to a 'NoneType' object Failed collecting trace Traceback (most recent call last): File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 259, in __call__ self.handle_call(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 213, in handle_call func = self._get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 207, in _get_func self.cache[code] = get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 151, in get_func func = get_func_in_mro(first_arg, code) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 113, in get_func_in_mro val = inspect.getattr_static(obj, code.co_name, None) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1622, in getattr_static instance_result = _check_instance(obj, attr) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1572, in _check_instance return dict.get(instance_dict, attr, _sentinel) TypeError: descriptor 'get' for 'dict' objects doesn't apply to a 'NoneType' object Failed collecting trace Traceback (most recent call last): File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 259, in __call__ self.handle_call(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 213, in handle_call func = self._get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 207, in _get_func self.cache[code] = get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 151, in get_func func = get_func_in_mro(first_arg, code) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 113, in get_func_in_mro val = inspect.getattr_static(obj, code.co_name, None) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1622, in getattr_static instance_result = _check_instance(obj, attr) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1572, in _check_instance return dict.get(instance_dict, attr, _sentinel) TypeError: descriptor 'get' for 'dict' objects doesn't apply to a 'NoneType' object Failed collecting trace Traceback (most recent call last): File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 259, in __call__ self.handle_call(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 213, in handle_call func = self._get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 207, in _get_func self.cache[code] = get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 151, in get_func func = get_func_in_mro(first_arg, code) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 113, in get_func_in_mro val = inspect.getattr_static(obj, code.co_name, None) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1622, in getattr_static instance_result = _check_instance(obj, attr) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1572, in _check_instance return dict.get(instance_dict, attr, _sentinel) TypeError: descriptor 'get' for 'dict' objects doesn't apply to a 'NoneType' object Failed collecting trace Traceback (most recent call last): File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 259, in __call__ self.handle_call(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 213, in handle_call func = self._get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 207, in _get_func self.cache[code] = get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 151, in get_func func = get_func_in_mro(first_arg, code) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 113, in get_func_in_mro val = inspect.getattr_static(obj, code.co_name, None) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1622, in getattr_static instance_result = _check_instance(obj, attr) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1572, in _check_instance return dict.get(instance_dict, attr, _sentinel) TypeError: descriptor 'get' for 'dict' objects doesn't apply to a 'NoneType' object Failed collecting trace Traceback (most recent call last): File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 259, in __call__ self.handle_call(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 213, in handle_call func = self._get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 207, in _get_func self.cache[code] = get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 151, in get_func func = get_func_in_mro(first_arg, code) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 113, in get_func_in_mro val = inspect.getattr_static(obj, code.co_name, None) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1622, in getattr_static instance_result = _check_instance(obj, attr) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1572, in _check_instance return dict.get(instance_dict, attr, _sentinel) TypeError: descriptor 'get' for 'dict' objects doesn't apply to a 'NoneType' object Failed collecting trace Traceback (most recent call last): File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 259, in __call__ self.handle_call(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 213, in handle_call func = self._get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 207, in _get_func self.cache[code] = get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 151, in get_func func = get_func_in_mro(first_arg, code) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 113, in get_func_in_mro val = inspect.getattr_static(obj, code.co_name, None) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1622, in getattr_static instance_result = _check_instance(obj, attr) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1572, in _check_instance return dict.get(instance_dict, attr, _sentinel) TypeError: descriptor 'get' for 'dict' objects doesn't apply to a 'NoneType' object Failed collecting trace Traceback (most recent call last): File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 259, in __call__ self.handle_call(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 213, in handle_call func = self._get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 207, in _get_func self.cache[code] = get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 151, in get_func func = get_func_in_mro(first_arg, code) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 113, in get_func_in_mro val = inspect.getattr_static(obj, code.co_name, None) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1622, in getattr_static instance_result = _check_instance(obj, attr) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1572, in _check_instance return dict.get(instance_dict, attr, _sentinel) TypeError: descriptor 'get' for 'dict' objects doesn't apply to a 'NoneType' object Failed collecting trace Traceback (most recent call last): File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 259, in __call__ self.handle_call(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 213, in handle_call func = self._get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 207, in _get_func self.cache[code] = get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 151, in get_func func = get_func_in_mro(first_arg, code) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 113, in get_func_in_mro val = inspect.getattr_static(obj, code.co_name, None) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1622, in getattr_static instance_result = _check_instance(obj, attr) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1572, in _check_instance return dict.get(instance_dict, attr, _sentinel) TypeError: descriptor 'get' for 'dict' objects doesn't apply to a 'NoneType' object Failed collecting trace Traceback (most recent call last): File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 259, in __call__ self.handle_call(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 213, in handle_call func = self._get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 207, in _get_func self.cache[code] = get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 151, in get_func func = get_func_in_mro(first_arg, code) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 113, in get_func_in_mro val = inspect.getattr_static(obj, code.co_name, None) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1622, in getattr_static instance_result = _check_instance(obj, attr) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1572, in _check_instance return dict.get(instance_dict, attr, _sentinel) TypeError: descriptor 'get' for 'dict' objects doesn't apply to a 'NoneType' object Failed collecting trace Traceback (most recent call last): File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 259, in __call__ self.handle_call(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 213, in handle_call func = self._get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 207, in _get_func self.cache[code] = get_func(frame) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 151, in get_func func = get_func_in_mro(first_arg, code) File "/Users/dap/Library/Python/3.9/lib/python/site-packages/monkeytype/tracing.py", line 113, in get_func_in_mro val = inspect.getattr_static(obj, code.co_name, None) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1622, in getattr_static instance_result = _check_instance(obj, attr) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 1572, in _check_instance return dict.get(instance_dict, attr, _sentinel) TypeError: descriptor 'get' for 'dict' objects doesn't apply to a 'NoneType' object Usage: python -m zwi [OPTIONS] COMMAND [ARGS]...

    need-info 
    opened by permezel 5
Owner
Instagram
Instagram
Re-apply type annotations from .pyi stubs to your codebase.

retype Re-apply type annotations from .pyi stubs to your codebase. Usage Usage: retype [OPTIONS] [SRC]... Re-apply type annotations from .pyi stubs

Łukasz Langa 131 Nov 17, 2022
Auto-generate PEP-484 annotations

PyAnnotate: Auto-generate PEP-484 annotations Insert annotations into your source code based on call arguments and return types observed at runtime. F

Dropbox 1.4k Dec 26, 2022
Awesome autocompletion, static analysis and refactoring library for python

Jedi - an awesome autocompletion, static analysis and refactoring library for Python Jedi is a static analysis tool for Python that is typically used

Dave Halter 5.3k Dec 29, 2022
A simple Python bytecode framework in pure Python

A simple Python bytecode framework in pure Python

null 3 Jan 23, 2022
a python refactoring library

rope, a python refactoring library ... Overview Rope is a python refactoring library. Notes Nick Smith <[email protected]> takes over maintaining rope

null 1.5k Dec 30, 2022
Find dead Python code

Vulture - Find dead code Vulture finds unused code in Python programs. This is useful for cleaning up and finding errors in large code bases. If you r

Jendrik Seipp 2.4k Dec 27, 2022
Safe code refactoring for modern Python.

Safe code refactoring for modern Python projects. Overview Bowler is a refactoring tool for manipulating Python at the syntax tree level. It enables s

Facebook Incubator 1.4k Jan 4, 2023
Programmatically edit text files with Python. Useful for source to source transformations.

massedit formerly known as Python Mass Editor Implements a python mass editor to process text files using Python code. The modification(s) is (are) sh

null 106 Dec 17, 2022
Bottom-up approach to refactoring in python

Introduction RedBaron is a python library and tool powerful enough to be used into IPython solely that intent to make the process of writing code that

Python Code Quality Authority 653 Dec 30, 2022
Removes commented-out code from Python files

eradicate eradicate removes commented-out code from Python files. Introduction With modern revision control available, there is no reason to save comm

Steven Myint 146 Dec 13, 2022
A library that modifies python source code to conform to pep8.

Pep8ify: Clean your code with ease Pep8ify is a library that modifies python source code to conform to pep8. Installation This library currently works

Steve Pulec 117 Jan 3, 2023
Code generation and code search for Python and Javascript.

Codeon Code generation and code search for Python and Javascript. Similar to GitHub Copilot with one major difference: Code search is leveraged to mak

null 51 Dec 8, 2022
AST based refactoring tool for Python.

breakfast AST based refactoring tool. (Very early days, not usable yet.) Why 'breakfast'? I don't know about the most important, but it's a good meal.

eric casteleijn 0 Feb 22, 2022
Refactoring Python Applications for Simplicity

Python Refactoring Refactoring Python Applications for Simplicity. You can open and read project files or use this summary ?? Concatenate String my_st

Mohammad Dori 3 Jul 15, 2022
Leap is an experimental package written to enable the utilization of C-like goto statements in Python functions

Leap is an experimental package written to enable the utilization of C-like goto statements in Python functions

null 6 Dec 26, 2022
Turn your C++/Java code into a Python-like format for extra style points and to make everyone hates you

Turn your C++/Java code into a Python-like format for extra style points and to make everyone hates you

Tô Đức (Watson) 4 Feb 7, 2022
A system for Python that generates static type annotations by collecting runtime types

MonkeyType MonkeyType collects runtime types of function arguments and return values, and can automatically generate stub files or even add draft type

Instagram 4.1k Dec 28, 2022
Runtime type annotations for the shape, dtype etc. of PyTorch Tensors.

torchtyping Type annotations for a tensor's shape, dtype, names, ... Turn this: def batch_outer_product(x: torch.Tensor, y: torch.Tensor) -> torch.Ten

Patrick Kidger 1.2k Jan 3, 2023
Tool for translation type comments to type annotations in Python

com2ann Tool for translation of type comments to type annotations in Python. The tool requires Python 3.8 to run. But the supported target code versio

Ivan Levkivskyi 123 Nov 12, 2022
Software to help automate collecting crowdsourced annotations using Mechanical Turk.

Video Crowdsourcing Software to help automate collecting crowdsourced annotations using Mechanical Turk. The goal of this project is to enable crowdso

Mike Peven 1 Oct 25, 2021