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 semantics of Record equality #1105
Fix semantics of Record equality #1105
Conversation
It should return the both the alt-specific and the fallback .lr filenames (in addition to the attachment filename.)
The SourceObject.source_filename property now just returns the first of the filenames returned by the iter_source_filenames method.
Both Records and VirtualSourceObjects are described by the identity key (path, alt, pad). That is, if obj2 = pad.get(obj.path, alt=obj.path) then obj2 == obj Records already had __eq__ and __hash__ methods which made this explicit. Here we add those methods for VirtualSourceObjects. Note this allows us to convert Context.referenced_virtual_dependencies from a dict to a set. (The key was only being used as an identity key for the VirtualSourceObjects.)
a9200b0
to
a1bdd9c
Compare
Can you elaborate more on the reason why the Pad has to be the same for equality? I am not sure but for me it just does not feel right. Path, page_num, and alt are properties that describe a specific page / end-point. Whereas Pad is the data structure that generates the page. I think I understand the reason behind the thinking (in a build process you want to know if you have seen the same object before), but I could imagine scenarios where you want to compare accross multiple builders to know if you are targeting the same page. |
Here's my thinking: Equality is a question of identity. Records from different pads are not the same and can not be used interchangeably. I could sort of see fudging this, if there were a common use-case that if facilitated — but even if one relaxes things so that record-equality doesn't depend on the Adjusting the semantics of equality to mean that two objects are "the same for some but not all purposes" seems likely to produce surprises. Especially in this case where we define a (If one does want to work across multiple pads, a useful abstraction would probably be to implement a |
* A sources identity depends on alt as well as path * Fix Attachment.iter_source_filenames It should return the both the alt-specific and the fallback .lr filenames (in addition to the attachment filename.) * SourceObject subclasses should all implement .iter_source_filenames The SourceObject.source_filename property now just returns the first of the filenames returned by the iter_source_filenames method. * Make the identity key (source, alt) explicit for VirtualSourceObjects Both Records and VirtualSourceObjects are described by the identity key (path, alt, pad). That is, if obj2 = pad.get(obj.path, alt=obj.path) then obj2 == obj Records already had __eq__ and __hash__ methods which made this explicit. Here we add those methods for VirtualSourceObjects. Note this allows us to convert Context.referenced_virtual_dependencies from a dict to a set. (The key was only being used as an identity key for the VirtualSourceObjects.)
These are bits extracted from the stale draft PR #1007.
It changes/fixes the equality semantics for
Records
andVirtualSourceObjects
so that they compare equal only if all of the following match:__class__
path
(which includespage_num
in the case ofPages
)alt
pad
Previously only
__class__
and_path
were compared, thus records with differingpage_num
,alt
, orpad
were comparing as equal.In general, a record is obtained by calling
pad.get(path, alt, page_num)
and a "different" record obtains if any ofpad
,path
,alt
, orpage_num
is changed.Other Changes
All SourceObjects should now implement iter_source_filenames
In general, the data comprising a
SourceObject
can come from multiple source files.This happens for Pages when alts are in use. It happens for attachments even when alts are not being used: an
Attachment
depends on both the attachment file and its corresponding metadata.lr
file.I suspect that we should deprecate the
SourceObject.source_filename
property altogether. The primary use ofsource_filename
oriter_source_filenames
is for dependency tracking — in that case, we always want to track all (potential) source files. In cases where a source object has multiple source files, 'm not sure the concept of a "primary" source file makes sense.New class: DBSourceObject
This PR introduces a
DBSourceObject
class. It is a subclass ofSourceObject
and serves as a superclass of all the object types that can be returned fromPad.get
.(The fixed equality comparison is implemented for
DBSourceObject
.)The new class hierarchy (for classes in the Lektor source which derive from
SourceObject
) isIssue(s) Resolved
Fixes #1101
Related Issues / Links
Description of Changes