Coder Social home page Coder Social logo

Comments (6)

Stewori avatar Stewori commented on September 22, 2024

First note that Tuple[(int, ...)] is no valid Python 2.7 code and pytypes assumes that type comments contain code that is compatible with the currently running interpreter (try to process test_type = Tuple[(int, ...)] in ordinary Python 2.7 code). I thought this is in line with PEP 484, because they demand all imports and locals/globals (e.g. type variables) required by code in type comments. Type comments are like usual code, just in a special position.

That said, I would actually like this to work anyway. I'm thinking of some text-based preprocessing hack that allows this to work on Python 2.7. I cannot promise now that I will be able to come up with something totally reasonable. We'll see...

(So I will label this an enhancement rather than a bug...)

from pytypes.

mitar avatar mitar commented on September 22, 2024

What would be an equivalent of Tuple[(int, ...)] in PYthon 2.7?

from pytypes.

Stewori avatar Stewori commented on September 22, 2024

I'm not sure. It might depend on the version of typing. From typing 3.5.3 onwards it might be

Tuple[(int, Ellipsis)]

Before that it might not be possible as a one-liner:

t = Tuple[(int,)]
t.__tuple_use_ellipsis__ = True

I did not yet find time to investigate this in more detail, so this answer is sort of preliminary. We will need some version-bridging utility method in pytypes for this. The old variant is still relevant as it's what is bundled with Python 3.5.

from pytypes.

Stewori avatar Stewori commented on September 22, 2024

Tuple[int, ...] seems to work perfectly fine in Python 2.7. Is there a special need for Tuple[(int, ...)] rather than Tuple[int, ...]?
Note that _issubclass_Tuple does not check regarding ellipsis case, but I am right now working to fix that, so ellipsis support for tuples should be available soon.
Given that Tuple[int, ...] works, I suppose we can close this issue... Thoughts?

from pytypes.

Stewori avatar Stewori commented on September 22, 2024

Ellipsis support was established a while ago. Given that Tuple[int, ...] syntax works fine I'll close this issue now. We can reopen if a good reason is presented. I'm also open to accept PRs that tweak the syntax parsing in typecomment_parser to support this. However, I consider it low priority at best...

from pytypes.

mitar avatar mitar commented on September 22, 2024

I also do not need it anymore. We move all our code to Python 3.

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.