Git Product home page Git Product logo

Comments (4)

m1schka avatar m1schka commented on May 17, 2024

not sure if it's related but I also have applied the types and it generated NoneType as a parameter, which is unknown to standard python and not getting added to the import (the only option would be to import it from monkeytype but I actually don't want monkeytype imports in my business code).

from monkeytype.

iamrajhans avatar iamrajhans commented on May 17, 2024

@carljm can i take this one

from monkeytype.

carljm avatar carljm commented on May 17, 2024

@m1schka Yeah, that's this bug. We have

elif anno is NoneType:
but it seems it's not effective (at least not in all cases). The correct fix here is that we should never generate NoneType at all in an annotation, it should always be translated to None.

@iamrajhans Sure, thank you!

from monkeytype.

johnarnold avatar johnarnold commented on May 17, 2024

I wrote a test case for this. It happens when types like Optional[str, NoneType] or even more complex occur.
My example:

    def test_union_nonetype_annotation(self):
        """NoneType should always be rendered as None"""
        sig = Signature.from_callable(UpdateSignatureHelper.has_annos)
        sig = update_signature_args(sig, {'a': Dict[str, Dict[str, Union[str, NoneType]]]}, has_self=False,
                                    ignore_existing_annotations=True)
        stub = FunctionStub('test', sig, FunctionKind.MODULE)
        expected = 'def test(a: Dict[str, Dict[str, Union[str, None]]], b) -> int: ...'
        assert stub.render() == expected

All the magic happens in render_annotations():
https://github.com/Instagram/MonkeyType/blob/master/monkeytype/stubs.py#L333

I'll submit a PR since this keeps biting me.

from monkeytype.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.