Coder Social home page Coder Social logo

Comments (5)

Stewori avatar Stewori commented on September 20, 2024

Thanks for spotting this issue. You're more than welcome to help out, my current priority is on fixing Python 3.7 support.

Some things to keep in mind:

  • For Python 2.7, we convert stubfiles to a 2.7 parsable form, i.e. using type comments and pass instead of .... These are potentially stored with .pyi2 suffix to avoid conflicts with Python 3 stubfiles in the same folder. See https://github.com/Stewori/pytypes#python-27-compliant-stubfiles.
  • In some situations (something with running module initialization code in a module involving forward references in stubfiles) certain checks must be delayed until module import is finished. In that case, pytypes monkeypatches builtins.__import__ for detecting end of module import. (This shall be turned into an import hook, but that's still a todo.) Just pointing this out, hope it does not interfere with your approach. The monkeypatch is only applied if such a situation really comes up. Also see pytypes.import_hook_enabled for controlling this behavior.
  • Currently pytypes also works with Jython. Keeping this compatibility valid can be tricky. I hope we can find a solution without breaking this support.
  • pytypes.stubfile_manager applies a bit more magic than just loading the stubfile. When classes are used as types or type parameters it assures that not the class objects from the stubfile are used but instead the corresponding class objects from the actual module. It was tricky to get this right for nested classes, which lead to somewhat complicated code in stubfile_manager.py. It might take additional consideration to integrate your approach with this mechanism. See e.g. stubfile_manager._match_stub_type or stubfile_manager._match_classes.

I cannot tell right now if any of these notes applies to your approach (e.g. I never tried to use contextlib in Jython, maybe it just works). It's just things that might have to be considered. Good luck and feel free to ask for advice on pytypes internals etc if required!

from pytypes.

Stewori avatar Stewori commented on September 20, 2024

I hope my comments did not scare you away. Please feel free to go on with a PR, even if it wouldn't consider all the points above right out of the box. We can fix these things together step by step (as far as necessary at all).

from pytypes.

gaborbernat avatar gaborbernat commented on September 20, 2024

@Stewori did not scare me away but me realize my current implementation has conceptional problems. E.g. does not handle forward references at all...

from pytypes.

Stewori avatar Stewori commented on September 20, 2024

Note that pytypes has a mechanism to handle forward references: type_util.resolve_fw_decl which takes a module name as (optional) parameter, denoting a module where it looks for declarations of referenced variables. I'm not sure right now if it works with a stub file as module, but if not we should add it there.

from pytypes.

gaborbernat avatar gaborbernat commented on September 20, 2024

I gave this a good thought and decide to do this instead at mypy level 😃

from pytypes.

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.