Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7587077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:35:03+00:00 2026-05-30T19:35:03+00:00

Specifically the :int part… I assumed it somehow checked the type of the parameter

  • 0

Specifically the “:int” part…

I assumed it somehow checked the type of the parameter at the time the function is called and perhaps raised an exception in the case of a violation. But the following run without problems:

def some_method(param:str):
    print("blah")

some_method(1)

def some_method(param:int):
    print("blah")

some_method("asdfaslkj")

In both cases “blah” is printed – no exception raised.

I’m not sure what the name of the feature is so I wasn’t sure what to google.

EDIT: OK, so it’s http://www.python.org/dev/peps/pep-3107/. I can see how it’d be useful in frameworks that utilize metadata. It’s not what I assumed it was. Thanks for the responses!

FOLLOW-UP QUESTION – Any thoughts on whether it’s a good idea or bad idea to define my functions as def some_method(param:int) if I really only can handle int inputs – even if, as pep 3107 explains, it’s just metadata – no enforcement as I originally assumed? At least the consumers of the methods will see clearly what I intended. It’s an alternative to documentation. Think this is good/bad/waste of time? Granted, good parameter naming (unlike my contrived example) usually makes it clear what types are meant to be passed in.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:35:04+00:00Added an answer on May 30, 2026 at 7:35 pm

    it’s not used for anything much – it’s just there for experimentation (you can read them from within python if you want, for example). they are called “function annotations” and are described in pep 3107.

    i wrote a library that builds on it to do things like type checking (and more – for example you can map more easily from JSON to python objects) called pytyp (more info), but it’s not very popular… (i should also add that the type checking part of pytyp is not at all efficient – it can be useful for tracking down a bug, but you wouldn’t want to use it across an entire program).

    [update: i would not recommend using function annotations in general (ie with no particular use in mind, just as docs) because (1) they might eventually get used in a way that you didn’t expect and (2) the exact type of things is often not that important in python (more exactly, it’s not always clear how best to specify the type of something in a useful way – objects can be quite complex, and often only “parts” are used by any one function, with multiple classes implementing those parts in different ways…). this is a consequence of duck typing – see the “more info” link for related discussion on how python’s abstract base classes could be used to tackle this…]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to convert Datetime fields to a specifically formatted INT type. For example,
Consider this code (Java, specifically): public int doSomething() { doA(); try { doB(); }
Specifically, is the following legal C++? class A{}; void foo(A*); void bar(const A&); int
Specifically, with a SortedMap<Vector<String>, int> I get dimensions expected after this ( int )
More specifically, if I have: public class TempClass : TempInterface { int TempInterface.TempProperty {
I am specifically thinking about unsigned int . Here is a practical example: what
In C++ specifically, what are the semantic differences between for example: static const int
if i don't specifically type a variable in my code will it compile as
Specifically this is regarding when using a client session cookie to identify a session
Specifically, what commands do I run from the terminal?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.