30

Python added type annotations, and since they're very new, there are a large number of questions about how to use them. People use different tags to mark these questions:

  1. and (140 questions)
  2. and (63 questions)
  3. (55 questions)
  4. and (49 questions)
  5. and (25 questions)

and occasionally something like (891 questions, almost none of which are about type annotations).

is the most actively used type checker, and all questions are actually just general type annotation questions, not specific to (at least I haven't seen any question specific to mypy extensions).

Should we manually change all these tags to the most popular one ( ) when we see them to make the tagging more consistent?

Too bad synonyms cannot be defined to map a pair of tags into a single tag or vice versa; otherwise we could map everything to the pair.

UPDATE:

I'll wait until Tuesday 4/11 to get any additional comments.

The concerns expressed by @BhargavRao is that automatic retagging will bump the new tag to the home page causing to be flooded with type-related questions. Currently, there are ~2.5 questions updated per minute. I'd retag questions at 1/10th of that rate, or 1 question every 4 minutes. This means retagging will complete within ~1 day (~300 questions total). Of course, I can lower the rate if someone thinks it's too fast.

The script logic I have in mind is:

  • Find all questions that are tagged with any of the tag combinations #2 through #5 (listed above) and that don't have .
  • Every 4 minutes, select one question, and if there's enough tag slots left, add .

I think removing tags is too dangerous, although I'm open to suggestions.

I'll share the script in case anyone wants to run it in the future again.

I hope that Stack Overflow automated tag suggestion system will notice that is used for questions with certain keywords, and will often suggest it for new typing-related questions.

If anyone has any ideas about how to use synonym system to help reduce inconsistent tagging of this topic, maybe add a comment?

EDIT: The retagging started. I removed a few irrelevant questions manually from the queue, and set the earliest allowed date to 2015-01-01 because PEP 484 was all but unknown until then. I also increased the delay to 10 min.

UPDATE: A moderator alerted me to the problem with my script unintentionally converting markdown to the much noisier HTML. I stopped the retagging and rolled back the changes. I do not want to risk automatic retagging again, even after I fix the problem. But if any moderator wants a list of questions that should be retagged, I have it.

8
  • 3
    Unless someone thinks it's a bad idea, I'll update all tags to add type-hinting if any of the other combinations is present.
    – max
    Commented Apr 9, 2017 at 20:02
  • 6
    I'd prefer type-hinting as the docs clearly mention that the module is a support for "type hints". And yes, mass retaging is a bad idea. You'll be bumping the tag to the home page and in the process, annoying multiple users who are following python.
    – Bhargav Rao Mod
    Commented Apr 9, 2017 at 20:15
  • 1
    I don't have an opinion about it but I would give it another 24 hours before you start. It is sunday in large parts of the world ....
    – rene
    Commented Apr 9, 2017 at 20:18
  • 1
    @BhargavRao is it ok to do it in small batches?
    – max
    Commented Apr 9, 2017 at 21:21
  • 19
    It's only been a few hours since you posted this proposal. It would be better to wait until you get some feedback from the community before embarking on a retagging project.
    – BJ Myers
    Commented Apr 10, 2017 at 0:38
  • 2
    Community managers have a tool to do batch retagging which does not bump the posts in the process.
    – user4639281
    Commented Apr 11, 2017 at 3:17
  • 1
    @TinyGiant So, should we ask community managers to do this instead of doing it from a user-level script?
    – max
    Commented Apr 11, 2017 at 3:41
  • 6
    If this initiative were to gain widespread support, that would be the least intrusive course of action.
    – user4639281
    Commented Apr 11, 2017 at 3:42

1 Answer 1

14

Before going to the conclusion, let me show you my query for Python-typing-related questions:

( and ) or ( and ) or ( and ) or ( and ) or ( and ) or or or or or or or or or

This query is, needless to say, unnecessarily humongous. And this is without the dreaded .

Conclusion:

I have edited the tag excerpt and retagged at least a thousand questions to this tag. I also find duplicates and post answers from time to time when applicable.
(My series of actions on recent days might have flooded some of your feeds and cause some of your badges to disappear, for which I apologize.)

There are only a few hundreds thousands left to be retagged, and the tag name itself is clear. I believe this is the way to go.

Its scope currently includes:

  • Typing PEPS
  • The typing module (and thus its cousins typing_extensions and typeshed/_typeshed)
  • Python's type system (and thus the typing specs)
  • Type-checking-time and runtime usages of type hints

Related tags

Here's how I deal with the tags:

  • A question is always about , so the latter should always be added. The former is a small tag, so doing this would help increase both the question and the tag's visibility.
  • should go with . This duo should be used for questions regarding only Pylance's language server features (hover, completion, go-to-definition, inlay hints, etc.). Questions about core type checking should use instead.
  • Question about configuring a tool should use the tag for that tool; might be unnecessary. Examples include but not limited to ignore comment syntax, rule enable- and disablement, API usage as well as internal details.
    • should be added to a question if the usage of type hints (including at runtime) is a major part of that question.
  • A might be about a specific type checker, in which case the tag for that type checker should be added, or it might be type-checker-agnostic, in which case + might be good enough.

Work left to do

Anyone interested are welcome to join me in curating the following:

Why haven't I write a program to do this automatically, you say? Multiple reasons:

  • The last time I tried to do so, SE banned my IP for 17 hours, saying I was making too many API calls, even though I have both an access token and a key, and I'm sure I had not exceed the limit (yet).
  • The API itself is terrible to work with.
  • Automated editing would not allow me to cast dupe votes, comment, post answers and the like.

Reference question

I have also created a reference question here. Contributions welcome.

18
  • 2
    "I have edited the tag excerpt and retagged at least a thousand questions to this tag." - kudos, from one veteran to another. Commented Jul 19 at 1:03
  • 2
    Noble to post an Answer 7 years later to this current Qt from 2017, but hum..., you could maybe also edit/update/improve the Qt which is currently hardly comprehensible in 2024-07 as it is about something "very new"(sic...!) but full of "EDIT" + "UPDATE" with a few vague dates in the Post without the year in unclear format [mm/dd] or [dd/mm](?), except one clear date in international format, but about 2015, = 2 years before the Thread was started.
    – chivracq
    Commented Jul 23 at 12:06
  • 1
    I only just noticed this post, I had actually searched for it 1 or 2 years ago but didn't find it. It's a bit old but that's ok. Keep on with the retag and if I come across something I'll do the same, it's long overdue!
    – bad_coder
    Commented Jul 27 at 11:48
  • I do have one reservation, it's this: there's a subtle distinction between type-hints and type annotations with some of Python SO posts on the subject having contradictory info e.g one example; another example among many out there (it's easier finding these examples on Google than using SO search). So I wished there'd be some community consensus if a retag were done to also choose one canonical and have the crowd sanity check it. Because it might be specialized tags be necessary.
    – bad_coder
    Commented Jul 27 at 11:53
  • So that's why I thought writing up a new meta post was necessary for this case. @KarlKnechtel please see my previous comments. If I remember correctly, taking all the PEPs together and the Python documentation - so the authoritative sources- I think I remember one place at least where a clear distinction was established in the terminology, but finding it is like a needle in a haystack and I've seen lots of users getting it wrong on SO (not that I could clearly state the difference now without first doing some extensive PEP research :P ).
    – bad_coder
    Commented Jul 27 at 11:56
  • @bad_coder In the vast majority of questions (those are not like the two you linked), they mean the same, especially when Python 2 has died and other usages of variable annotations are deprecated. Python 2 typing questions are so few and so rare that I don't think we need a separate tag.
    – InSync
    Commented Jul 27 at 12:32
  • Regarding the terminology, I think you are referring to the specification; it does have a glossary, but "type annotation" and "type hint" don't have official definitions.
    – InSync
    Commented Jul 27 at 12:33
  • @InSync "Variable annotations are usually used for type hints:"... The sentence implies there's a difference iow "one being used for the other" means they're not the same. The Python glossary always seemed incomplete (maintaining a glossary is actually very complicated) I find it hard to believe that "the Python glossary" -if you care to count- could only have 23 terms.
    – bad_coder
    Commented Jul 27 at 12:52
  • This is to say that I've read all of those documents several times over these past years, and as has often been the PEP 20 case "there's a (supposedly) obvious" definition from how the terms are used except it isn't obvious and there's no clear definition at all, just differences in usage suggesting the terms are different... And that's why a MSO post would be necessary.
    – bad_coder
    Commented Jul 27 at 12:53
  • @bad_coder That's because, from the language/interpreter's perspective, the annotations are mere attachments. While the main use is for type hinting, technically people can still use annotations for something else. In the old days, they were also used for documentation, and evidently some libraries even use them to create a DSL.
    – InSync
    Commented Jul 27 at 12:58
  • @InSync ok, so how many cases are there with potentially different names? Argument annotation, return annotation, variable annotation, function annotation, type comments and using the annotation for something different than a type. I agree with putting all things Python typing in a single tag, but afterwards isn't there something left to be desired? Is there some sense in having more specialized tags? Anyway, at least the main goal is being achieved of being able to search everything about Python typing using a single tag - that's an improvement!
    – bad_coder
    Commented Jul 27 at 13:17
  • @bad_coder No, I don't think so, not for the different places where type hints can be put. However, I do see generics, type-variables, inheritance, subclass/subclassing (these should be merged), oop (this is utter useless), abc, mixins, multiple-inheritance, etc. Sometimes I remove them, sometimes I don't.
    – InSync
    Commented Jul 27 at 13:25
  • @bad_coder PEP 526 has this: "PEP 484 introduced type hints, a.k.a. type annotations." And, to be pedantic, mostly everything; tool-specific questions (configurations and such, see my tag guidance in the post) might not have python-typing.
    – InSync
    Commented Jul 27 at 18:26
  • @InSync originally posted 2016 last revision 2024... There are dozens of 484 related PEPs by now, any confusion is the PEPs' fault as I'm sure I've read them attentively. And that's not to mention when they announced all type hints were going to become strings only to back out on that statement or the 2.6k mypy bugs. Telling folks what Python really is can come across as unbelievable if you're used to languages with a manufacturer.
    – bad_coder
    Commented Jul 27 at 19:31
  • @InSync but no, I do not agree that mypy Qs should have the python-typing tag removed, because if that happens users will again have to do 2 searches for typing related stuff since most of the times typing questions are checked with mypy (although pure tool config Qs might dispense the python-typing tag, on that I do agree).
    – bad_coder
    Commented Jul 27 at 19:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .