Tuesday, February 9, 2016

Undecoratable

Decorators are one of Python's bigger success stories, and many programmers' first experience with higher-order programming. Most practiced and prolific Python programmers will find themselves making good use of them regularly.

But every feature has its limits, and here's a new one to try on for size:

>>> @x().y()
  File "<stdin>", line 1
    @x().y()
        ^
SyntaxError: invalid syntax

That's right, decoration is not an arbitrary Python expression. It doesn't matter what x and y were, or even if they were defined. You can't follow a function call with a dot. @x() works fine, @x.y() would work fine, too. But @x().y(), that's only for mad Pythonists who would take things TOO FAR.

Decorator invocations, defined at the top of the Python grammar, can only be followed by class definitions and function definitions.

Well, now we know, and now we can all say we've been there

-- Mahmoud
http://sedimental.org/
https://github.com/mahmoud
https://twitter.com/mhashemi

18 comments:

  1. Great blog.you put Good stuff.All the topics were explained briefly.so quickly understand for me.I am waiting for your next fantastic blog.Thanks for sharing.Any coures related details learn...

    Best AWS Training Institute in Chennai | AWS Training Center in Chennai | AWS Certification Exams in Velachery | AWS Exams in OMR

    ReplyDelete
  2. Thank you for your information. I have got some important suggestions from it. Keep on sharing.Very informative blog. Helps to gain knowledge about new concepts and techniques.
    Linux Training in Velachery | Linux Training Institute in Chennai | Linux Training in Kanchipuram

    ReplyDelete
  3. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge.
    Selenium course in Chennai | Selenium Certification in Chennai | Selenium course in Velachery

    ReplyDelete
  4. Very interesting topic. Helps to gain knowledge about lot of information. Thanks for information in this blog.
    Blue Prism course in Chennai | Blue Prism Certification in Chennai | Blue Prism course in Velachery

    ReplyDelete
  5. Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating...
    Blue Prism Certification in Chennai | Blue Prism Exam Center in Velachery | Blue Prism Online Exam Center in Chennai | Blue Prism Exams in Velachery

    ReplyDelete
  6. This is really too useful and have more ideas from yours. Keep sharing many techniques. Eagerly waiting for your new blog and useful information. Keep doing more.
    Selenium Training Center in Chennai | Selenium Training Center in Velachery | Selenium Training Center in Kanchipuram

    ReplyDelete
  7. Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating...
    Blue Prism Exam Center in Chennai | Blue Prism Exam Center in Velachery | Blue Prism Exam Center in Kanchipuram

    ReplyDelete
  8. Great blog.you put Good stuff.All the topics were explained briefly.so quickly understand for me.I am waiting for your next fantastic blog.Thanks for sharing.Any coures related details learn...
    Python Training Institute in Chennai | Python Exam Center in Chennai | Python Certification in Taramani | Python Training in OMR | Python Exams in Velachery

    ReplyDelete
  9. Great post and informative blog. It was awesome to read, thanks for sharing this great content to my vision.
    Blue Prism Training in Chennai | Blue Prism Training Center in Velachery | Blue Prism Course in Chennai

    ReplyDelete
  10. Thanks for sharing information to our knowledge, it helps me plenty keep sharing….I am pretty much pleased with your good work. You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.

    Linux Training in Velachery | Linux Training Institute in Chennai | Linux Training in Kanchipuram

    ReplyDelete
  11. All the points you described so beautiful. Every time i read your blog content and i so surprised that how you can write so well.
    Blue Prism Training in Velachery | Blue Prism Certification in Velachery | Blue Prism Exam Center in Chennai

    ReplyDelete
  12. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
    Selenium Certification in Chennai | Selenium Training Center in Velachery | Selenium course in Kanchipuram

    ReplyDelete
  13. Your blog is very informative with useful information, thanks a lot for sharing such a wonderful article, its very useful for me. Keep updating your creative knowledge....
    Blue Prism Training in Chennai | Blue Prism Certification in Chennai | Blue Prism Exam Center in Chennai

    ReplyDelete