Wednesday, February 24, 2021

Python Bytes: #222 Autocomplete with type annotations for AWS and boto3

<p>Sponsored by <strong>Linode!</strong> <a href="https://pythonbytes.fm/linode"><strong>pythonbytes.fm/linode</strong></a></p> <p>Special guest: Greg Herrera</p> <p>YouTube live stream for viewers: </p> <a href='https://www.youtube.com/watch?v=hiQgsF1JfmU' style='font-weight: bold;'>Watch on YouTube</a><br> <br> <p><strong>Michael #1:</strong> <a href="https://pypi.org/project/boto3-type-annotations/"><strong>boto type annotations</strong></a></p> <ul> <li>via Michael Lerner</li> <li><code>boto3</code>'s services are created at runtime</li> <li>IDEs aren't able to index its code in order to provide code completion or infer the type of these services or of the objects created by them. </li> <li>Type systems cannot verify them</li> <li>Even if it was able to do so, clients and service resources are created using a service agnostic factory method and are only identified by a string argument of that method.</li> <li><code>boto3_type_annotations</code> defines stand in classes for the clients, service resources, paginators, and waiters provided by <code>boto3</code>'s services.</li> </ul> <p>Example with <strong>“bare”</strong> boto3:</p> <p><img src="https://trello-attachments.s3.amazonaws.com/58e3f7c543422d7f3ad84f33/603430a72669028e981eaff8/eb88f93ed86b21e20b775d9c34047fd3/without-boto-types.png" alt="" /></p> <p>Example with <strong>annotated</strong> boto3:</p> <p><img src="https://trello-attachments.s3.amazonaws.com/58e3f7c543422d7f3ad84f33/603430a72669028e981eaff8/063160043ed426111d5f8c7bf0d332f9/with-boto-types.png" alt="" /></p> <p><strong>Brian #2:</strong> <a href="https://mtlynch.io/code-review-love/"><strong>How to have your code reviewer appreciate you</strong></a></p> <ul> <li>By Michael Lynch</li> <li>Suggested by Miłosz Bednarzak</li> <li>Actual title “How to Make Your Code Reviewer Fall in Love with You” <ul> <li>but 🤮</li> <li>even has the words “<strong>your reviewer will literally fall in love with you.”</strong> </li> <li>literally → figuratively, please</li> </ul></li> <li><strong>Topic is important though, here are some good tips:</strong> <ul> <li>Review your own code first <ul> <li>“Don’t just check for mistakes — imagine reading the code for the first time. What might confuse you?”</li> </ul></li> <li>Write a clear change list description</li> <li>“A good change list description explains <strong>what</strong> the change achieves, at a high level, and <strong>why</strong> you’re making this change.”</li> <li>Narrowly scope changes</li> <li>Separate functional and non-functional changes</li> <li>This is tough, even for me, but important.</li> <li>Need to fix something, and the formatting is a nightmare and you feel you must blacken it. Do those things in two separate merge requests. </li> <li>Break up large change lists</li> <li>A ton to write about. Maybe it deserves 2-3 merges instead of 1. </li> <li>Respond graciously to critiques</li> <li>It can feel like a personal attack, but hopefully it’s not.</li> <li>Responding defensively will only make things works.</li> </ul></li> </ul> <p><strong>Greg #3:</strong> <strong><a href="https://laurencemolloy.github.io/RepoDash/">REPODASH</a> - Quality Metrics for Github repositories</strong></p> <ul> <li>by Laurence Molloy</li> <li>Do you maintain a project codebase on Github?</li> <li>Would you like to be able to show the maturity of your project at a glance?</li> <li>Walk through the metrics available</li> <li>Use-case</li> </ul> <p><strong>Michael #4: Extra, extra, extra, extra, hear all about it</strong></p> <ul> <li><a href="https://nvd.nist.gov/vuln/detail/CVE-2021-3177">Python 3 Float Security Bug</a></li> <li><a href="https://towardsdatascience.com/building-python-from-source-on-ubuntu-20-04-2ed29eec152b">Building Python 3 from source now</a> :-/ It’s still Python 3.8.5 on Ubuntu with the kernel patch just today! (Linux 5.4.0-66 / Ubuntu 20.04.2)</li> <li>Finally, I’m <strong>Dockering on my M1 mac</strong> via:</li> <li><code>docker context create remotedocker --docker "host=ssh://user@server"</code></li> <li><code>docker context use remotedocker</code></li> <li><p><code>docker run -it ubuntu:latest bash</code> now works as usual but remotely! <img src="https://ift.tt/3aPQWcx" alt="" /></p></li> <li><p>Why I keep complaining about merge thing on <a href="https://dependabot.com/"><strong>dependabot</strong></a>. Why!?! ;) <img src="https://ift.tt/3dLl1vU" alt="" /></p></li> <li><p><a href="https://twitter.com/anthonypjshaw/status/1360322334050066433">Anthony Shaw</a> wrote <a href="https://twitter.com/anthonypjshaw/status/1360322334050066433">a bot</a> to help alleviate this a bit. More on that later.</p></li> </ul> <p><strong>Brian #5:</strong> <a href="https://testcontainers-python.readthedocs.io/en/latest/"><strong>testcontainers-python</strong></a></p> <ul> <li><a href="https://twitter.com/_neozenith/status/1361875720046141446">Suggested by Josh Peak</a></li> <li>Why mock a database? Spin up a live one in a docker container. </li> <li>“Python port for testcontainers-java that allows using docker containers for functional and integration testing. Testcontainers-python provides capabilities to spin up docker containers (such as a database, Selenium web browser, or any other container) for testing.”</li> </ul> <pre><code>import sqlalchemy from testcontainers.mysql import MySqlContainer with MySqlContainer('mysql:5.7.32') as mysql: engine = sqlalchemy.create_engine(mysql.get_connection_url()) version, = engine.execute("select version()").fetchone() print(version) # 5.7.32 </code></pre> <ul> <li>The snippet above will spin up a MySql database in a container. The <code>get_connection_url()</code> convenience method returns a <code>sqlalchemy</code> compatible url we use to connect to the database and retrieve the database version.</li> </ul> <p><strong>Greg #6:</strong> <strong>The Python Ecosystem is relentlessly improving price-performance every day</strong></p> <ul> <li>Python is reaching top-of-mind for more and more business decision-makers because their technology teams are delivering solutions to the business with unprecedented price-performance. </li> <li>The business impact keeps getting better and better. </li> <li>What seems like heavy adoption throughout the economy is still a relatively small-inroad compared to what we’ll see in the future. It’s like water rapidly collecting behind a weak dam.</li> <li>It’s an exciting time to be in the Python world! </li> </ul> <p>Extras:</p> <p>Brian: </p> <ul> <li>Firefox 86 enhances cookie protection <ul> <li>sites can save cookies. but can’t share between sites. </li> <li>Firefox maintains separate cookie storage for each site.</li> <li>Momentary exceptions allowed for some non-tracking cross-site cookie uses, such as popular third party login providers.</li> </ul></li> </ul> <p><img src="https://trello-attachments.s3.amazonaws.com/58e3f7c543422d7f3ad84f33/60369190de10756b8269462d/33714e729f44f1e0b73c85fa0c938cd6/cookies.png" alt="" /></p> <p>Joke:</p> <p><a href="https://betterprogramming.pub/56-funny-code-comments-that-people-actually-wrote-6074215ab387">56 Funny Code Comments That People Actually Wrote</a>: These are actually in a code base somewhere (a sampling):</p> <pre><code> /* * Dear Maintainer * * Once you are done trying to ‘optimize’ this routine, * and you have realized what a terrible mistake that was, * please increment the following counter as a warning * to the next guy. * * total_hours_wasted_here = 73 */ </code></pre> <pre><code> // sometimes I believe compiler ignores all my comments </code></pre> <pre><code> // drunk, fix later </code></pre> <pre><code> // Magic. Do not touch. </code></pre> <pre><code> /*** Always returns true ***/ public boolean isAvailable() { return false; } </code></pre>

from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...