
kamalfarahani
Python Testing with pytest, Second Edition: Typing mistake (page 13)
In the Card
class definition, the type hints for the summary
, owner
, and id
attributes are currently specified as str
, str
, and int
respectively, with default values of None
.
@dataclass
class Card:
owner: str = None
summary: str = None
state: str = "todo"
id: int = field(default=None, compare=False)
This is a minor mistake. To accurately reflect that these fields are optional and can be None
, they should be defined using Optional
from the typing
module. The corrected type hints are:
-
owner
should beOptional[str]
-
summary
should beOptional[str]
-
id
should beOptional[int]
The corrected class definition would appear as follows (assuming from typing import Optional
is present):
from typing import Optional
@dataclass
class Card:
owner: Optional[str] = None
summary: Optional[str] = None
state: str = "todo"
id: Optional[int] = field(default=None, compare=False)
Popular Pragmatic Bookshelf topics

Hi! I know not the intentions behind this narrative when called, on page XI:
mount() |> handle_event() |> render()
but the correc...
New

#book-python-testing-with-pytest-second-edition
Hi. Thanks for writing the book. I am just learning so this might just of been an issue ...
New

I’m new to Rust and am using this book to learn more as well as to feed my interest in game dev. I’ve just finished the flappy dragon exa...
New

I’m running Android Studio “Arctic Fox” 2020.3.1 Patch 2, and I’m embarrassed to admit that I only made it to page 8 before running into ...
New

This is as much a suggestion as a question, as a note for others.
Locally the SGP30 wasn’t available, so I ordered a SGP40. On page 53, ...
New

I think I might have found a problem involving SwitchCompat, thumbTint, and trackTint.
As entered, the SwitchCompat changes color to hol...
New

“The ProductLive.Index template calls a helper function, live_component/3, that in turn calls on the modal component. ”
Excerpt From: Br...
New

I’m not quite sure what’s going on here, but I’m unable to have to containers successfully complete the Readiness/Liveness checks. I’m im...
New

I’m a newbie to Rails 7 and have hit an issue with the bin/Dev script mentioned on pages 112-113.
Iteration A1 - Seeing the list of prod...
New

It seems the second code snippet is missing the code to set the current_user:
current_user: Accounts.get_user_by_session_token(session["...
New
Other popular topics

Reading something? Working on something? Planning something? Changing jobs even!?
If you’re up for sharing, please let us know what you’...
New

What chair do you have while working… and why?
Is there a ‘best’ type of chair or working position for developers?
New

A PragProg Hero’s Journey with Brian P. Hogan @bphogan
Have you ever worried that your only legacy will be in the form of legacy...
New

New

You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New

There’s a whole world of custom keycaps out there that I didn’t know existed!
Check out all of our Keycaps threads here:
https://forum....
New

Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
New

Author Spotlight
James Stanier
@jstanier
James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New

Rails 7 completely redefines what it means to produce fantastic user experiences and provides a way to achieve all the benefits of single...
New

Author Spotlight
Erin Dees
@undees
Welcome to our new author spotlight! We had the pleasure of chatting with Erin Dees, co-author of ...
New
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /rails
- /js
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /ash
- /vscode
- /opensuse
- /centos
- /php
- /deepseek
- /html
- /scala
- /zig
- /debian
- /nixos
- /lisp
- /sublime-text
- /textmate
- /agda
- /react-native
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /django
- /manjaro
- /spring
- /diversity
- /lua
- /nodejs
- /julia
- /c
- /slackware
- /neovim