Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix model field default value generating in cases when this is the only one constraint #393

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/atproto_client/models/app/bsky/actor/defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class KnownFollowers(base.ModelBase):
class AdultContentPref(base.ModelBase):
"""Definition model for :obj:`app.bsky.actor.defs`."""

enabled: bool = None #: Enabled.
enabled: bool = False #: Enabled.

py_type: t.Literal['app.bsky.actor.defs#adultContentPref'] = Field(
default='app.bsky.actor.defs#adultContentPref', alias='$type', frozen=True
Expand Down Expand Up @@ -228,7 +228,7 @@ class FeedViewPref(base.ModelBase):
hide_replies_by_like_count: t.Optional[
int
] = None #: Hide replies in the feed if they do not have this number of likes.
hide_replies_by_unfollowed: t.Optional[bool] = None #: Hide replies in the feed if they are not by followed users.
hide_replies_by_unfollowed: t.Optional[bool] = True #: Hide replies in the feed if they are not by followed users.
hide_reposts: t.Optional[bool] = None #: Hide reposts in the feed.

py_type: t.Literal['app.bsky.actor.defs#feedViewPref'] = Field(
Expand Down Expand Up @@ -271,7 +271,7 @@ class MutedWord(base.ModelBase):
value: str = Field(max_length=10000) #: The muted word itself.
actor_target: t.Optional[
t.Union[t.Literal['all'], t.Literal['exclude-following'], str]
] = None #: Groups of users to apply the muted word to. If undefined, applies to all users.
] = 'all' #: Groups of users to apply the muted word to. If undefined, applies to all users.
expires_at: t.Optional[
str
] = None #: The date and time at which the muted word will expire and no longer be applied.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Params(base.ParamsModelBase):
t.Literal['posts_and_author_threads'],
str,
]
] = None #: Combinations of post/repost types to include in response.
] = 'posts_with_replies' #: Combinations of post/repost types to include in response.
limit: t.Optional[int] = Field(default=50, ge=1, le=100) #: Limit.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Params(base.ParamsModelBase):
] = None #: Filter results for posts after the indicated datetime (inclusive). Expected to use 'sortAt' timestamp, which may not match 'createdAt'. Can be a datetime, or just an ISO date (YYYY-MM-DD).
sort: t.Optional[
t.Union[t.Literal['top'], t.Literal['latest'], str]
] = None #: Specifies the ranking order of results.
] = 'latest' #: Specifies the ranking order of results.
tag: t.Optional[
t.List[str]
] = None #: Filter to posts with the given tag (hashtag), based on rich-text facet or tag field. Do not include the hash (#) prefix. Multiple tags can be specified, with 'AND' matching.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Params(base.ParamsModelBase):
"""Parameters model for :obj:`app.bsky.labeler.getServices`."""

dids: t.List[str] #: Dids.
detailed: t.Optional[bool] = None #: Detailed.
detailed: t.Optional[bool] = False #: Detailed.


class ParamsDict(t.TypedDict):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Params(base.ParamsModelBase):
] = None #: Filter results for posts after the indicated datetime (inclusive). Expected to use 'sortAt' timestamp, which may not match 'createdAt'. Can be a datetime, or just an ISO date (YYYY-MM-DD).
sort: t.Optional[
t.Union[t.Literal['top'], t.Literal['latest'], str]
] = None #: Specifies the ranking order of results.
] = 'latest' #: Specifies the ranking order of results.
tag: t.Optional[
t.List[str]
] = None #: Filter to posts with the given tag (hashtag), based on rich-text facet or tag field. Do not include the hash (#) prefix. Multiple tags can be specified, with 'AND' matching.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Params(base.ParamsModelBase):
"""Parameters model for :obj:`chat.bsky.moderation.getMessageContext`."""

message_id: str #: Message id.
after: t.Optional[int] = None #: After.
before: t.Optional[int] = None #: Before.
after: t.Optional[int] = 5 #: After.
before: t.Optional[int] = 5 #: Before.
convo_id: t.Optional[
str
] = None #: Conversation that the message is from. NOTE: this field will eventually be required.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Params(base.ParamsModelBase):

cursor: t.Optional[str] = None #: Cursor.
limit: t.Optional[int] = Field(default=100, ge=1, le=500) #: Limit.
sort: t.Optional[t.Union[t.Literal['recent'], t.Literal['usage'], str]] = None #: Sort.
sort: t.Optional[t.Union[t.Literal['recent'], t.Literal['usage'], str]] = 'recent' #: Sort.


class ParamsDict(t.TypedDict):
Expand Down
2 changes: 1 addition & 1 deletion packages/atproto_client/models/com/atproto/label/defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class LabelValueDefinition(base.ModelBase):
] = None #: Does the user need to have adult content enabled in order to configure this label?
default_setting: t.Optional[
t.Union[t.Literal['ignore'], t.Literal['warn'], t.Literal['hide'], str]
] = None #: The default setting for this label.
] = 'warn' #: The default setting for this label.

py_type: t.Literal['com.atproto.label.defs#labelValueDefinition'] = Field(
default='com.atproto.label.defs#labelValueDefinition', alias='$type', frozen=True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class Data(base.DataModelBase):
"""Input data model for :obj:`com.atproto.server.createInviteCodes`."""

code_count: int = None #: Code count.
code_count: int = 1 #: Code count.
use_count: int #: Use count.
for_accounts: t.Optional[t.List[str]] = None #: For accounts.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Params(base.ParamsModelBase):

create_available: t.Optional[
bool
] = None #: Controls whether any new 'earned' but not 'created' invites should be created.
include_used: t.Optional[bool] = None #: Include used.
] = True #: Controls whether any new 'earned' but not 'created' invites should be created.
include_used: t.Optional[bool] = True #: Include used.


class ParamsDict(t.TypedDict):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Params(base.ParamsModelBase):
has_comment: t.Optional[bool] = None #: If true, only events with comments are returned.
include_all_user_records: t.Optional[
bool
] = None #: If true, events on all record types (posts, lists, profile etc.) owned by the did are returned.
] = False #: If true, events on all record types (posts, lists, profile etc.) owned by the did are returned.
limit: t.Optional[int] = Field(default=50, ge=1, le=100) #: Limit.
removed_labels: t.Optional[
t.List[str]
Expand All @@ -43,7 +43,7 @@ class Params(base.ParamsModelBase):
report_types: t.Optional[t.List[str]] = None #: Report types.
sort_direction: t.Optional[
t.Union[t.Literal['asc'], t.Literal['desc']]
] = None #: Sort direction for the events. Defaults to descending order of created at timestamp.
] = 'desc' #: Sort direction for the events. Defaults to descending order of created at timestamp.
subject: t.Optional[str] = None #: Subject.
types: t.Optional[
t.List[str]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ class Params(base.ParamsModelBase):
review_state: t.Optional[str] = None #: Specify when fetching subjects in a certain state.
reviewed_after: t.Optional[str] = None #: Search subjects reviewed after a given timestamp.
reviewed_before: t.Optional[str] = None #: Search subjects reviewed before a given timestamp.
sort_direction: t.Optional[t.Union[t.Literal['asc'], t.Literal['desc']]] = None #: Sort direction.
sort_field: t.Optional[t.Union[t.Literal['lastReviewedAt'], t.Literal['lastReportedAt']]] = None #: Sort field.
sort_direction: t.Optional[t.Union[t.Literal['asc'], t.Literal['desc']]] = 'desc' #: Sort direction.
sort_field: t.Optional[
t.Union[t.Literal['lastReviewedAt'], t.Literal['lastReportedAt']]
] = 'lastReportedAt' #: Sort field.
subject: t.Optional[str] = None #: Subject.
tags: t.Optional[t.List[str]] = None #: Tags.
takendown: t.Optional[bool] = None #: Get subjects that were taken down.
Expand Down
17 changes: 6 additions & 11 deletions packages/atproto_codegen/models/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ def _get_model_field_value( # noqa: C901
min_length = field_type_def.min_length
if field_type_def.max_length is not None:
max_length = field_type_def.max_length
# TODO (MarshalX): support knownValue, format, enum?

elif field_type == models.LexBoolean:
if field_type_def.default is not None:
Expand Down Expand Up @@ -311,21 +310,17 @@ def _get_model_field_value( # noqa: C901
if value is not_set:
continue

if name != 'default':
only_default = False
str_value = f"'{value}'" if isinstance(value, str) else str(value)

value_str = f'{name}='
if isinstance(value, str):
value_str += f"'{value}'"
elif isinstance(value, bool):
value_str += 'True' if value else 'False'
if name == 'default':
default = str_value
else:
value_str += str(value)
only_default = False

values.append(value_str)
values.append(f'{name}={str_value}')

if only_default:
return 'None'
return default

if not values:
return ''
Expand Down
Loading